<template>
    <div class="device-list">
        <div class="device-list-container flex-container">
            <el-row class="search-row">
                <el-col :span="24">
                    <el-form :inline="true" :model="searchForm" class="demo-form-inline">
                        <el-form-item label="审核状态">
                            <el-select v-model="searchForm.status" >
                                <el-option
                                        v-for="item in searchStatusList"
                                        :key="item.id"
                                        :label="item.value"
                                        :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item class="pull-right">
                            <el-button type="primary" @click="clearSearchOption">清空</el-button>
                            <el-button type="success" @click="_orderEvaluationList()">查询</el-button>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>

            <div class="device-list-table">

                <el-table :data="orderEvaluationList" border>

                    <el-table-column label="ID" prop="id" width="120"></el-table-column>
                    <el-table-column label="评价用户">
                        <template slot-scope="scope">
                            {{scope.row.nickname}}
                        </template>
                    </el-table-column>
                    <el-table-column label="评价内容">
                        <template slot-scope="scope">
                            {{scope.row.content}}
                        </template>
                    </el-table-column>
                    <el-table-column label="审核状态">
                        <template slot-scope="scope">
                            <!--{{scope.row.status_name}}-->

                            <el-select v-model="scope.row.status" @change="selectChange($event, scope.row.id)">
                                <el-option
                                        v-for="item in statusList"
                                        :key="item.id"
                                        :label="item.value"
                                        :value="item.id">
                                </el-option>
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" fixed="right" width="200">
                        <template slot-scope="scope">
                            <el-button size="mini" type="danger outline"
                                       @click="handleDelete(scope.$index, scope.row)">
                                删除
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>

            <div class="flex-footer h-80">
                <div class="flex-footer-content">
                    <el-row>
                        <el-col :span="8" class="pt-6">
                            &nbsp;
                            <!--<el-button type="success" @click="handleAddUser">添加用户</el-button>-->
                        </el-col>
                        <el-col :span="16" class="text-right" v-if="total > 0">
                            <el-pagination
                                    @current-change="pageChange"
                                    :current-page="currentPage"
                                    :page-size="pageSize"
                                    layout="total, prev, pager, next, jumper"
                                    :total="total">
                            </el-pagination>
                        </el-col>
                    </el-row>
                </div>
            </div>
        </div>

        <!--编辑弹窗-->
        <el-dialog title="更新到指定账户" custom-class="edit-dialog" :visible.sync="editModalVisible">
            <el-form :label-position="'left'" label-width="110px" ref="userForm" :model="userForm">
                <el-form-item label="目标用户名" prop="target_user_id">

                </el-form-item>
                <el-form-item label="目标分组">

                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="success" @click="saveUser('userForm')">确认更新</el-button>
            </div>
        </el-dialog>


    </div>
</template>

<script type="text/ecmascript-6">

    import Core from 'core/core'

    export default {
        data() {
            return {
                editModalVisible: false,
                userForm: {},
                orderEvaluationList: [],

                statusList: [
                    {id: 5, value: "待审核"},
                    {id: 10, value: "审核通过"},
                    {id: 15, value: "审核未通过"},
                ],
                searchForm: {
                    status: "",
                },
                searchStatusList: [
                    {id: "", value: "全部"},
                    {id: 5, value: "待审核"},
                    {id: 10, value: "审核通过"},
                    {id: 15, value: "审核未通过"},
                ],

                // 分页配置
                currentPage: 1,
                total: 0,
                pageSize: 10,
            }
        },
        mounted: function () {
            this._orderEvaluationList();
        },

        methods: {
            clearSearchOption() {
                this.searchForm.status = "";
                this._orderEvaluationList()
            },
            _orderEvaluationList() {
                Core.Api.OrderEvaluation.list(this.currentPage, this.searchForm.status)
                    .then(res => {
                        this.orderEvaluationList = res.list;
                        this.total = res.count
                    })
                    .catch(err => {
                    })
            },

            pageChange(val) {
                this.currentPage = val;
                this._orderEvaluationList();
            },

            saveUser(formName) {

            },

            handleDelete(index, row) {
                this.$alert('确认删除吗?', {
                    confirmButtonText: '确定',
                    callback: action => {
                        if (action == 'confirm') {
                            Core.Api.OrderEvaluation.deleteOrderEvaluation(row.id)
                                .then(res => {

                                    this.$message.success("删除成功");
                                    this._orderEvaluationList();
                                })
                        }
                    }
                });
            },

            selectChange(event, id) {
                Core.Api.OrderEvaluation.audit(id, event)
                    .then(res => {
                        this.$message.success("审核状态更新成功")
                    })
                    .catch(res => {
                    })
            }

        }
    }
</script>

<style scoped lang="scss">
    .device-list {
        height: 100%;
        .device-list-container {
            height: 100%;
            .search-row {
                margin: 0;
                padding: 15px 30px;
                background: #fff;
                .el-form--inline .el-form-item {
                    margin-bottom: 0;
                }
                .el-form-item__label {
                    padding-right: 10px;
                    font-size: 12px;
                }
                .el-form-item__content {
                    .el-input {
                        width: 175px;
                    }
                }
            }

            .device-list-table {
                padding: 20px 0;
                background: #ffffff;
                position: relative;
                flex: 1;
                overflow: auto;
                .all-select-holder {
                    line-height: 30px;
                    position: absolute;
                    left: 10px;
                    z-index: 10;
                }
            }
            .flex-footer {
                border-top: 1px solid #E0E7EF;
            }
            .flex-footer.h-80 {
                height: 80px;
            }

        }

        a.success {
            display: inline-block;
            color: #fff;
            background-color: #03CC75;
            border-color: #03CC75;
            line-height: 1;
            white-space: nowrap;
            cursor: pointer;
            -webkit-appearance: none;
            text-align: center;
            box-sizing: border-box;
            outline: none;
            -moz-user-select: none;
            -webkit-user-select: none;
            -ms-user-select: none;
            padding: 7px 16px;
            font-size: 12px;
            border-radius: 4px;
            margin: 0 10px;
        }

        .upload-device {
            display: inline-block;
        }
    }
</style>
